//
//  TFWelcomeViewController.swift
//  weiboSina
//
//  Created by admin on 15/12/30.
//  Copyright © 2015年 admin. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class TFWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        imageView.sd_setImageWithURL(NSURL(string: (TFUserAccountViewModel.sharedViewModel.userAccount?.avatar_large)!), placeholderImage: UIImage(named: "avatar_default_big"))
        
        setupUI()
}

    
    private func setupUI(){
    
    view.backgroundColor = UIColor(white: 0.97, alpha: 1)
        //添加控件
        view.addSubview(imageView)
        view.addSubview(messageLabel)
    
    //添加约束
        imageView.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(view.snp_top).offset(200)
            make.size.equalTo(CGSize(width: 90, height: 90))
            
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(imageView)
            make.top.equalTo(imageView.snp_bottom).offset(15)
        }
        
        
        
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        //现更改约束
        
        imageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view.snp_top).offset(100)
        }
        
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            // 如果界面需要重新布局,就去 layout
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
            UIView.animateWithDuration(1, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        // 跳转到首页
                        // 发送一个切换根控制器的通知
             print("切换界面")
            NSNotificationCenter.defaultCenter().postNotificationName(HMSwitchRootViewControllerNotification, object: nil)
                })
        }
    }
    
    
// MARK: - 懒加载控件
   private lazy var imageView: UIImageView = {
        
        let v = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        //设置圆角
        v.layer.cornerRadius = 45
        v.layer.masksToBounds = true
        //设置边界
        v.layer.borderColor = UIColor.lightGrayColor().CGColor
        v.layer.borderWidth = 1
        
        return v
    }()
    
    
    //欢迎标签
    
  private  lazy var messageLabel: UILabel = {
    
    let l = UILabel()
        l.text = "欢迎回来"
    l.alpha = 0
        l.textColor = UIColor.darkGrayColor()
        l.sizeToFit()
        return l
    
    }()
}